#include <iostream>
#include <vector>
using namespace std;

class Solution {
public:
    vector<int> plusOne(vector<int>& digits) {
        vector<int> ret;

        digits[digits.size() - 1] += 1;
        int t = 0;
        for (int i = digits.size() - 1; i >= 0; --i) {
            ret.push_back((digits[i] + t) % 10);
            t = (digits[i] + t) / 10;
        }
        if (t) {
            ret.push_back(t % 10);
            ret.push_back(t / 10);
        }
        if (ret.back() == 0) ret.pop_back();

        reverse(ret.begin(), ret.end());
        return ret;
    }
};

int main()
{
    vector<int> digits = { 9, 9 };
    Solution().plusOne(digits);
    return 0;
}